package com.zr.action;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.Cuser;
import com.zr.service.UserService;

@Controller
@Scope(value="prototype")
public class UserAction extends  ActionSupport  implements  ServletResponseAware,SessionAware{
	private  Cuser user;
	private  HttpServletResponse  resp;
    private  Map<String,Object> session; 

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.resp = response;
		
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		this.session=arg0;
	}
	public Cuser getUser() {
		return user;
	}

	public void setUser(Cuser user) {
		this.user = user;
	}

	@Resource
	private  UserService  userService;
	
	public void login(){
		 Cuser cuser= userService.findUserByUrootAndUpsw(user.getUroot(),user.getUpassword());
		 System.out.println();
		 PrintWriter out;
		try {
			out = resp.getWriter();
			if("已注销".equals(cuser.getUstate())){
				out.write("2");
				out.flush();
				out.close();
			}else{
				if(cuser.getUid()>0){
					session.put("cuser", cuser);
					 out.write("1");
					 out.flush();
					 out.close();
				 }else{
					 out.write("0");
					 out.flush();
					 out.close();
				 }
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
	}

}
